<!DOCTYPE html>
<html	xmlns="http://www.w3c.org/1999/xhtml"
		xmlns:h="http://xmlns.jcp.org/jsf/html"
		xmlns:f="http://java.sun.com/jsf/core"
		xmlns:ui="http://java.sun.com/jsf/facelets"
		xmlns:fn="http://java.sun.com/jsp/jstl/functions"
		xmlns:p="http://primefaces.org/ui">
<h:head>
<style type="text/css">
</style>
</h:head>
<h:body>
	<p:panelGrid columns="2" columnClasses="column30,column70" style="width:80%;height:80%;" >
		<p:treeTable	id="myTreeTable" style="width:100%;height:100%;" 
						value="#{searchBean.root}" var="document" 
						selectionMode="checkbox" selection="#{searchBean.selectedNodes}">
			<f:facet name="header">
				Email File Browser
				<p:menuButton value="Actions">
					<p:menuitem value="Refresh" actionListener="#{searchBean.refreshTree}" update="myTreeTable" icon="ui-icon-arrowrefresh-1-w"/>
					<p:menuitem value="Delete" actionListener="#{searchBean.deleteFiles}" update="myTreeTable" icon="ui-icon-close"/>
					<p:menuitem value="Scan" rendered="#{adminBean.admin}" actionListener="#{searchBean.scanFiles}" update=":myForm:messages" icon="ui-icon-zoomin"/>
				</p:menuButton>
			</f:facet>
			<p:column headerText="Name">
				<h:outputText value="#{document.name}" />
			</p:column>						
			<p:column headerText="Size">
				<h:outputText value="#{document.size}" />
			</p:column>						
		</p:treeTable>
	
		<p:panelGrid columns="1" style="width:100%;">
			<p:remoteCommand 	name="doSearch" action="#{searchBean.search}" 
								update="myResult, myExeTime" global="true"/>
	
			<p:panelGrid 	columns="3" style="width:100%;" 
							id="searchPanelGrid" columnClasses="column60,column10,column30">
				<p:inputText 	style="width:98%;" value="#{searchBean.key}" 
								onkeypress="if(event.keyCode==13){doSearch();return false;}"/>
				<p:commandButton	value="Search" update="myResult, myExeTime" 
									action="#{searchBean.search}" ajax="true" 
									styleClass="ui-priority-primary" global="true"/>
				<h:outputText 	id="myExeTime" value="#{searchBean.executionTime}" 
								style="font-weight:bold" />
			</p:panelGrid>
			
			<p:panel id="myResult" style="border:0px;">
				<ui:repeat value="#{searchBean.displayedEmails}" var="em">
					<p:panel style="border:0px;">
						<p:commandLink 	style="text-decoration: none;" 
										update=":emailDetail" global="true"
										action="#{searchBean.onClickEmail(em.id)}"
										oncomplete="PF('dtlDialog').show()">
							<h:outputText value="#{em.summary}" /> 
						</p:commandLink> 
					</p:panel>
				</ui:repeat>
				<p:panel style="border:0px;" rendered="#{not searchBean.showSearchResult}">
					<h:outputText value="No Match Found." />
				</p:panel>
				<p:separator rendered="#{searchBean.showSearchResult}"/>
				<p:panel style="border:0px;" rendered="#{searchBean.showSearchResult}">
					<p:commandLink 	update=":myForm:myTabView:myResult, :myForm:myTabView:myExeTime" 
									rendered="#{searchBean.showPrev}" global="true"
									actionListener="#{searchBean.onClickPrevPage}">
						<h:outputText value="Previous" />
					</p:commandLink>
					<h:outputText value="" style="margin-left:10px;"/>
					<ui:repeat value="#{searchBean.pageNumbers}" var="pn">
						<p:commandLink	update=":myForm:myTabView:myResult, :myForm:myTabView:myExeTime" 
										rendered="#{not pn.current}" global="true"
										actionListener="#{searchBean.onClickPage(pn.num)}">
							<h:outputText value="#{pn.num}" />
						</p:commandLink>
						<h:outputText value="#{pn.num}" rendered="#{pn.current}" style="font-weight:bold;font-size:15px;"/>
						<h:outputText value="" style="margin-left:10px;"/>
					</ui:repeat>
					<h:outputText rendered="#{not searchBean.allFetched}" value="..."/>
					<h:outputText value="" style="margin-left:10px;"/>
					<p:commandLink 	update=":myForm:myTabView:myResult, :myForm:myTabView:myExeTime" 
									rendered="#{searchBean.showNext}" global="true"
									actionListener="#{searchBean.onClickNextPage}">
						<h:outputText value="Next" />
					</p:commandLink>
				</p:panel>
			</p:panel>
		</p:panelGrid>
	</p:panelGrid>
</h:body>
</html>
